<template>
  <div class="app-container">
  <el-divider content-position="left">
    <label style="color: red;font-weight: bold;">目前工具商品仅支持从该「
      <a href="https://union.jd.com/proManager/index?pageNo=1" target="_blank">https://union.jd.com/proManager/index?pageNo=1</a>」链接搜索的京东商品-》左侧-[我要推广]->[商品推广]</label>
  </el-divider>
  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-row type="flex" justify="start" align="top" :gutter="15">
      <el-form-item label="商品分类" required>
        <el-input v-model="ruleForm.cateId" :style="{width: '600px'}" placeholder="请输入商品分类右侧的ID(目前最多支持1个)"></el-input>
      </el-form-item>
      <el-form-item label="入库类型" required>
        <el-select v-model="ruleForm.type" placeholder="入库类型">
          <el-option label="商品入库" value="0"></el-option>
          <el-option label="目前不支持评论入库" value="1"></el-option>
        </el-select>
      </el-form-item>
    </el-row>
      <el-form-item label="商品SUK" required>
        <el-input type="textarea" :rows="15" v-model="ruleForm.skuId" placeholder="请输入商品suk(目前最多支持1个)"></el-input>
      </el-form-item>
    <el-form-item>
    <el-button type="primary" @click="submitForm" :loading='loadingbut'>立即执行</el-button>
    <el-button @click="resetForm('ruleForm')">重置</el-button>
    </el-form-item>
  </el-form>
</div>
</template>

<script>
import { inertShopGoodsJsonData} from '@/api/tools/alipay'
import { Message } from 'element-ui'
export default {
  data() {
    return {
      ruleForm: {
        cateId: '',
        skuId:'',
        type: '0'
      },
      loadingbut:false,
      rules: {
        cateId: [
          { required: true, message: '请输入商品分类', trigger: 'blur' }
        ],
        type: [
          { type: 'array', required: true, message: '请至少选择一个活动性质', trigger: 'change' }
        ],
        skuId: [
          { required: true, message: '请选择活动资源', trigger: 'change' }
        ],
        desc: [
          { required: true, message: '请填写活动形式', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    submitForm() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          this.loadingbut = true
          inertShopGoodsJsonData(this.ruleForm).then(res => {
            this.loadingbut = false
            Message({ message: '录入成功', type: 'success' })
          }).catch(err => {
            this.loadingbut = false
            console.log(err.response.data.message)
          })
        } else {
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
